﻿#ifndef MYMAINWINDOW_H
#define MYMAINWINDOW_H
#include <QMainWindow>
#include <QWidget>
#include <QTextEdit>
#include <QDockWidget>
#include <QVBoxLayout>
#include <QTableWidget>
#include <QLabel>
#include <QMouseEvent>
#include <QAction>
#include <QActionGroup>
#include <QMenuBar>
#include <QMenu>
#include <QToolBar>
#include <QToolButton>
#include <QStatusBar>
#include "ImageView.h"

class MyMainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MyMainWindow(char *fileName_=NULL, QWidget *parent = 0);
    ~MyMainWindow(){}

protected:
    ImageView      *centralView;
    QToolBar       *typeSelected;
    QStatusBar     *statusBar;
    QSlider        *frameslider;
    QTimer         *vis_timer_;
    QVector<QAction*>   objButtons;
    QAction        *block, *tree, *woodenBridg, *mound, *holes;

    QAction        *openA, *closeA, *exitA, *copyA, *cutA, *pasteA;
    QString        m_imageName,m_typeName;
    QLabel         *labelTypeName,*labelImageName;

    bool play_mode_ = false;

    void   initToolBar(void);
    void   initMenuBar(void);
    void   initStateBar(void);
    void   initAction(void);

    virtual void mousePressEvent(QMouseEvent *event)
    {
        centralView->mousePressEvent(event);
        return QMainWindow::mousePressEvent(event);
    }
    virtual void mouseReleaseEvent(QMouseEvent *event)
    {
        centralView->mouseReleaseEvent(event);
        return QMainWindow::mouseReleaseEvent(event);
    }
    virtual void keyPressEvent(QKeyEvent *event)
    {
        centralView->keyPressEvent(event);
        return QMainWindow::keyPressEvent(event);
    }
signals:

public slots:
    void changeTypeName(QAction* type_){
        m_typeName = type_->text();
        labelTypeName->setText(m_typeName);
    }
    void changeImageName(QString name_){
        m_imageName = name_;
        labelImageName->setText(m_imageName);
        //        Message->setText("<strong><font color=red>Process: Image Index ["
        //                         +m_imageName+"]       Type: ["+m_typeName +"]</font></strong>");
    }

    void playButtonPressed()
    {
        play_mode_ = true;
    }

    void stopButtonPressed()
    {
        play_mode_ = false;
    }

    void backButtonPressed()
    {
        if (centralView->currentIndex == 0) // Allready in the beginning
        {
            centralView->currentIndex = centralView->totalLine - 1; // reset to end
            frameslider->setSliderPosition(centralView->currentIndex);        // Update the slider position
        }
        else
        {
            centralView->currentIndex--;
            frameslider->setSliderPosition(centralView->currentIndex);        // Update the slider position
        }
    }

    void nextButtonPressed()
    {
        if (centralView->currentIndex == (centralView->totalLine - 1)) // Reached the end
        {
            centralView->currentIndex = 0; // reset to beginning
            frameslider->setSliderPosition(centralView->currentIndex);
        }
        else
        {
            centralView->currentIndex++;
            frameslider->setSliderPosition(centralView->currentIndex);  // Update the slider position
        }
    }

    void timeoutSlot() {
        if (play_mode_) {
            if (centralView->currentIndex == (centralView->totalLine - 1)) // Reached the end
            {
                centralView->currentIndex = 0; // reset to beginning
                frameslider->setSliderPosition(centralView->currentIndex);
            }
            else
            {
                centralView->currentIndex++;
                frameslider->setSliderPosition(centralView->currentIndex);  // Update the slider position
            }
        }
    }
};

#endif // MYMAINWINDOW_H
